package com.hmdp.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Slf4j
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 当前ThreadlLocal获取不到用户 则设置状态码并拦截
        if (UserHolder.getUser() == null) {
            response.setStatus(401);
            return false; // 拦截
        }
        return true;
    }
}
